﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace Devotit.Umbraco.MvcBridge.Html
{
    public class CaptureContext : IDisposable
    {
        private HttpContextBase context { get; set; }
        private TextWriter originalOutput {get; set;}
        public StringWriter CaptureOutput { get; private set; }

        public CaptureContext(HttpContextBase context)
        {
            CaptureOutput = new StringWriter();
            originalOutput = context.Response.Output;
            this.context = context;

            context.Response.Output = CaptureOutput;
        }

        public string GetOutput()
        {
            return CaptureOutput.GetStringBuilder().ToString();
        }

        public void Dispose()
        {
            context.Response.Output = originalOutput;
            CaptureOutput.Dispose();
        }
    }
}